<?php
/**
*配送计划管理
*
 *  */
namespace app\index\controller;

use app\common\YujisoController;
use app\index\service\DistributionService;
class Distribution extends YujisoController
{
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        exitJson(DistributionService::getList($this->param));
    }
    //详情 创建 修改
    public function create(){
        $param=$this->request->post();
        if ($this->request->isPost()) {
            
            $list=json_decode($param['list'],true);
            unset($param['list']);
            $param['list']=$list;
            if($this->param['id']){
                //编辑
                $res=DistributionService::create($param);
            }else{
                //新建
                $res=DistributionService::create($param);
            }
            exitJson($res);
        } else {
            //详情
            exitJson(DistributionService::detail($this->param));
        }
    }
    //编辑页面返回明细
    public function detail(){
        exitJson(DistributionService::detail($this->param));
    }
    //审核
    public function audithandle(){
        exitJson(DistributionService::audit($this->param));
    }
    public function detailTemp(){
        returnJson(1);
    }
    //上传明细
    public function upload(){
        $param=request()->param();
        $param['title']=['sku','数量'];//必须校验头部
        $param['actionAsync']='\app\index\service\DistributionService::uploadHandle';//上传数据的数据回调到service层处理
        $res=\app\common\service\ExcelLibraryService::read($param);
        exitJson($res);
    }
    public function getCompany(){
        $param=request()->param();
        if(empty($param['country_id'])){
            returnJson('0','国家不能为空');
        }
      //  $type=$param['type']==1 ? [2,3]:[2,3,4];
        
        $listout=\app\common\model\ToolModel::select('base_company',['status'=>1,'type'=>['in',[2,3]],'base_country_id'=>$param['country_id']],'company_name','','id');  
        $listrecieve=\app\common\model\ToolModel::select('base_company',['status'=>1,'type'=>['in',[2,3,4]],'base_country_id'=>$param['country_id']],'company_name','','id'); 
        returnJson('1','',["1"=>$listout,"2"=>$listrecieve]);
    }
    public function getShopWarehouse(){
        $param=request()->param();
        $type=$param['type']==1 ? 1:2;
        DistributionService::getShopWarehouse($param,$type);
    }
    public function getWarehouseByShopId(){
        $param=request()->param();
        if(empty($param['shop_id'])){
            returnJson('0','商铺不能为空');
        }
        DistributionService::getWarehouseByShopId($param['shop_id']);
    }
}